﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Charisma.Tests
{
    public static class EntityConfiguratorExtensions
    {
        private static FieldInfo members;
        private static FieldInfo keyMember;
        private static FieldInfo entityType;

        public static Dictionary<MemberInfo, EntityMemberConfigurator> GetMembers(this EntityConfigurator configurator)
        {
            return (Dictionary<MemberInfo, EntityMemberConfigurator>)members.GetValue(configurator);
        }

        public static MemberInfo GetKeyMember(this EntityConfigurator configurator)
        {
            return (MemberInfo)keyMember.GetValue(configurator);
        }

        public static Type GetEntityType(this EntityConfigurator configurator)
        {
            return (Type)entityType.GetValue(configurator);
        }

        static EntityConfiguratorExtensions()
        {
            var c = typeof(EntityConfigurator);
            members = c.GetField("Members", BindingFlags.Instance | BindingFlags.NonPublic);
            keyMember = c.GetField("KeyMember", BindingFlags.Instance | BindingFlags.NonPublic);
            entityType = c.GetField("EntityType", BindingFlags.Instance | BindingFlags.NonPublic);
        }
    }
}
